Skip to content

feat: show popup menu on NotifyHeader more button click - #1457

Merged
yixinshark merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-notifycenterMenu
Feb 27, 2026
Merged

yixinshark merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-notifycenterMenu

Conversation

@yixinshark

@yixinshark yixinshark commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor
  • The more button in NotifyHeader previously called openNotificationSetting() directly on click

  • Now it shows a NotifySettingMenu popup with a "Notification Setting" menu item, consistent with GroupNotify's more button behavior

  • The menu is positioned centered below the more button

  • Uses the existing NotifySettingMenu component with modal and close-on-outside-click behavior

  • NotifyHeader 的 more 按钮之前点击直接调用 openNotificationSetting()

  • 现在改为弹出 NotifySettingMenu 菜单,包含"Notification Setting"选项

  • 与 GroupNotify 的 more 按钮行为保持一致

  • 菜单居中显示在按钮下方,使用已有的 NotifySettingMenu 组件

Log: show popup menu on NotifyHeader more button click
Pms: BUG-284815

Summary by Sourcery

Show a popup notification settings menu from the NotifyHeader "more" button instead of opening settings directly.

New Features:

  • Add a NotifySettingMenu popup to the NotifyHeader more button with a "Notification Setting" menu item.

Enhancements:

  • Align NotifyHeader more button behavior and menu positioning with the existing GroupNotify notification settings menu.

@sourcery-ai

sourcery-ai Bot commented Feb 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

NotifyHeader’s more button now opens a positioned popup NotifySettingMenu instead of directly invoking the notification settings API, aligning its behavior with GroupNotify and delegating the actual settings action to a menu item click.

Sequence diagram for NotifyHeader more button popup menu flow

sequenceDiagram
    actor User
    participant NotifyHeader
    participant moreBtn
    participant NotifySettingMenu
    participant MenuItem_NotificationSetting
    participant NotifyAccessor

    User->>NotifyHeader: click more button
    NotifyHeader->>moreBtn: handle onClicked
    moreBtn->>NotifySettingMenu: set x and y for positioning
    moreBtn->>NotifySettingMenu: toggle()
    NotifySettingMenu-->>User: display popup menu

    User->>MenuItem_NotificationSetting: click
    MenuItem_NotificationSetting->>NotifyAccessor: openNotificationSetting()
    NotifyAccessor-->>User: show notification settings screen
Loading

Class diagram for NotifyHeader and NotifySettingMenu integration

classDiagram
    class NotifyHeader {
    }

    class moreBtn {
        +int width
        +int height
        +onClicked()
    }

    class NotifySettingMenu {
        +int x
        +int y
        +toggle()
    }

    class MenuItem_NotificationSetting {
        +string text
        +onClicked()
    }

    NotifyHeader *-- moreBtn
    NotifyHeader *-- NotifySettingMenu : headerSettingMenu
    NotifySettingMenu *-- MenuItem_NotificationSetting
Loading

File-Level Changes

Change Details Files
Change NotifyHeader more button behavior to open a popup menu instead of directly calling notification settings.
  • Replace direct NotifyAccessor.openNotificationSetting() call in the more button click handler with logic to position and toggle a popup menu
  • Log message updated to reflect opening of the settings menu rather than the settings page
  • Position the popup menu centered horizontally under the more button using its dimensions
panels/notification/center/NotifyHeader.qml
Integrate NotifySettingMenu component into NotifyHeader with a menu item that triggers notification settings.
  • Add a NotifySettingMenu instance scoped to the header with an id used by the more button click handler
  • Define a single MenuItem labeled "Notification Setting" that, when clicked, logs and then calls NotifyAccessor.openNotificationSetting()
  • Rely on the existing NotifySettingMenu component behavior (modal and close-on-outside-click) for user interaction
panels/notification/center/NotifyHeader.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Positioning the NotifySettingMenu using headerSettingMenu.width before the menu is shown may yield incorrect centering; consider basing the x/y on implicitWidth/implicitHeight or positioning in an onAboutToShow/onOpened handler so the menu size is known.
  • If the intent is always to open the menu on click rather than toggling visibility, replacing headerSettingMenu.toggle() with an explicit open call (e.g., open()/visible = true) would avoid accidental closing from rapid or repeated clicks.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Positioning the `NotifySettingMenu` using `headerSettingMenu.width` before the menu is shown may yield incorrect centering; consider basing the x/y on `implicitWidth/implicitHeight` or positioning in an `onAboutToShow`/`onOpened` handler so the menu size is known.
- If the intent is always to open the menu on click rather than toggling visibility, replacing `headerSettingMenu.toggle()` with an explicit open call (e.g., `open()`/`visible = true`) would avoid accidental closing from rapid or repeated clicks.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@yixinshark
yixinshark force-pushed the fix-notifycenterMenu branch 2 times, most recently from 5e66b2f to db74d57 Compare February 27, 2026 03:38
- The more button in NotifyHeader previously called
  openNotificationSetting() directly on click
- Now it shows a NotifySettingMenu popup with a "Notification Setting"
  menu item, consistent with GroupNotify's more button behavior
- The menu is positioned centered below the more button
- Uses the existing NotifySettingMenu component with modal and
  close-on-outside-click behavior

- NotifyHeader 的 more 按钮之前点击直接调用 openNotificationSetting()
- 现在改为弹出 NotifySettingMenu 菜单,包含"Notification Setting"选项
- 与 GroupNotify 的 more 按钮行为保持一致
- 菜单居中显示在按钮下方,使用已有的 NotifySettingMenu 组件

Log: show popup menu on NotifyHeader more button click
Pms: BUG-284815
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这段代码的 diff 展示了对 NotifyHeader.qml 文件的修改,主要是将原本点击按钮直接打开通知设置页面的逻辑,修改为点击按钮弹出一个菜单,菜单中包含"Notification Setting"选项,点击该选项才打开设置页面。

以下是对这段代码的审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • 版权年份更新:将版权年份从 2024 更新为 2024 - 2026 是合理的做法,表示代码维护的预期周期。

  • 菜单定位逻辑:

    headerSettingMenu.x = moreBtn.width / 2 - headerSettingMenu.width / 2
    headerSettingMenu.y = moreBtn.height

    这段逻辑试图将菜单居中显示在按钮下方。然而,这里存在一个潜在的逻辑缺陷:headerSettingMenu.width 在菜单第一次显示之前可能未正确计算或为 0(取决于 QML 的加载顺序和布局策略)。这会导致菜单第一次弹出时位置偏移,或者在 toggle() 调用时发生位置跳动。

    • 改进建议:建议将菜单定位逻辑放在 headerSettingMenu.aboutToShow() 信号中处理,或者确保菜单的 width 已经绑定好。如果希望菜单相对于按钮定位,更稳健的做法是使用 parent 坐标映射或者将菜单作为按钮的子元素(如果层级允许)。
  • 菜单定义位置:
    NotifySettingMenu 被直接定义在了 MouseArea 的脚本块 onClicked 之后。虽然在 QML 中这种写法在语法上是允许的(作为兄弟元素),但这并不是最佳实践。它使得代码结构看起来像是菜单属于点击事件的一部分,容易造成阅读困惑。

    • 改进建议:将 NotifySettingMenu 的定义移到 moreBtn(即包含 MouseArea 的组件)的同级作用域中,或者文件末尾,保持组件结构的扁平化和清晰。

2. 代码质量

  • 硬编码文本:qsTr("Notification Setting") 是正确的做法,支持国际化,值得肯定。
  • 调试代码残留:
    console.log("Notify setting menu")
    // ...
    console.log("Notification setting")
    代码中保留了 console.log。虽然在开发阶段这是必要的,但在提交代码或发布版本时,应移除或使用条件编译(如 Qt.debug())包裹,以免污染生产环境的控制台输出并带来微小的性能开销。
  • 组件复用性:目前菜单中只有一个选项。如果未来计划添加更多选项(如"清除所有通知"、"勿扰模式"等),当前的封装方式是可行的。如果确定只有这一个选项,增加一层菜单反而增加了用户的点击成本(交互深度),降低了用户体验。

3. 代码性能

  • 对象创建:NotifySettingMenu 是在 QML 加载时创建的,而不是在点击时动态创建。这是正确的做法,避免了点击时的卡顿。
  • 布局计算:如前所述,在 onClicked 中计算坐标并立即显示可能涉及布局重算。如果菜单内容复杂,可能会有轻微性能影响,但对于简单的文本菜单通常可以忽略。

4. 代码安全

  • 输入验证:代码主要涉及 UI 交互,没有外部输入处理,因此安全性风险较低。
  • 权限与调用:NotifyAccessor.openNotificationSetting() 是外部调用。假设 NotifyAccessor 是已注册且受控的单例或全局对象,此调用是安全的。需确保 NotifyAccessor 不允许被恶意注入或重写。

综合改进建议代码示例

为了解决菜单定位问题和代码结构问题,建议对代码进行如下调整:

// ... 其他代码 ...

FocusScope {
    // ... 其他属性和组件 ...

    // 将菜单定义移到更外层,作为 FocusScope 的直接子元素
    NotifySettingMenu {
        id: headerSettingMenu
        
        // 使用 aboutToShow 确保在显示前计算位置,此时 width 已就绪
        onAboutToShow: {
            // 将坐标转换到父容器坐标系,确保定位准确
            // 假设 moreBtn 是 headerSettingMenu 的兄弟元素
            var pos = moreBtn.mapToItem(headerSettingMenu.parent, 0, moreBtn.height)
            headerSettingMenu.x = pos.x + (moreBtn.width / 2) - (headerSettingMenu.width / 2)
            headerSettingMenu.y = pos.y
        }

        MenuItem {
            text: qsTr("Notification Setting")
            onClicked: {
                // 生产环境建议移除 console.log
                NotifyAccessor.openNotificationSetting()
            }
        }
    }

    // ... 按钮定义 ...
    Button {
        id: moreBtn
        // ... 其他属性 ...

        onClicked: function () {
            // 仅负责切换显示状态,不处理坐标
            headerSettingMenu.toggle()
        }
    }
}

总结

这段代码的功能实现没有大问题,主要问题在于菜单定位的时机和代码结构的组织。通过调整菜单定义的位置和利用 onAboutToShow 进行坐标计算,可以提高代码的健壮性和可维护性。同时,建议清理调试日志。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wjyrich, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yixinshark
yixinshark merged commit 7bbda28 into linuxdeepin:master Feb 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants